      Module Mathematic_Manipulation_Module
    
      Implicit None
    
      Contains
    
      Attributes(Device) Subroutine Principal_Stress_Direction3_GPU(Sigxx,Sigyy,Sigxy,Pstr1,Pstr2,Tau12,Angle)

!.... To Calculate Second Order Tensor Rotation
!.... Angle Is The Angle Princpal Stresses Make With X-Axis
!.... In Radian (Anti-Clockwise)
      
      Implicit None
!.... Input Variables
      Double Precision Sigxx,Sigyy,Sigxy
!.... Output Variables
      Double Precision Pstr1,Pstr2,Angle,Tau12
!.... Local Variables
      Double Precision Sinth,Costh
      Costh=Cos(Angle)
      Sinth=Sin(Angle)
      Pstr1=Sigxx*(Costh*Costh)+Sigyy*(Sinth*Sinth)+(2.0D0*Sigxy*(Sinth*Costh))          
      Pstr2=Sigxx*(Sinth*Sinth)+Sigyy*(Costh*Costh)-(2.0D0*Sigxy*(Sinth*Costh))           
      Tau12=Sinth*Costh*(Sigyy-Sigxx)+(Costh*Costh-Sinth*Sinth)*Sigxy
      Return
      End

  

      Attributes(Device) Double Precision Function Sum_Absolute_Value_GPU(N,Dx,Incx)

!.... Takes The Sum Of The Absolute Values.

      Double Precision Dx(N),Dtemp
      Integer I,Incx,M,Mp1,N,Nincx

      Sum_Absolute_Value_GPU = 0.0D0
      Dtemp = 0.0D0
      If(N.Le.0) Return
      If(Incx.Eq.1) Goto 20

!.... Code For Increment Not Equal To 1

      Nincx = N*Incx
      Do I = 1,Nincx,Incx
         Dtemp = Dtemp + Dabs(Dx(I))
      End Do
      Sum_Absolute_Value_GPU = Dtemp
      Return

!.... Code For Increment Equal To 1
!.... Clean-Up Loop

   20 M = Mod(N,6)
      If( M .Eq. 0 ) Goto 40
      Do I = 1,M
        Dtemp = Dtemp + Dabs(Dx(I))
      End Do
      If( N .Lt. 6 ) Goto 60
   40 Mp1 = M + 1
      Do I = Mp1,N,6
        Dtemp = Dtemp + Dabs(Dx(I)) + Dabs(Dx(I + 1)) + Dabs(Dx(I + 2))+ Dabs(Dx(I + 3)) + Dabs(Dx(I + 4)) + Dabs(Dx(I + 5))        
      End Do
   60 Sum_Absolute_Value_GPU = Dtemp
      Return
      End
    
      
    
    
      End Module